#pragma once

#if defined(_WIN32) || defined(__ICCARM__)
#pragma pack(1)
#endif

#include "transfer.h"

typedef struct _MotorEncoder
{
  _u32 ticksDeltaL;
  _u32 ticksDeltaR;
} __attribute__((packed)) MotorEncoder;



typedef struct _Speed
{
  _s32 left_wheel;
  _s32 right_wheel;
} __attribute__((packed)) Speed;

static MotorEncoder motorEncoder;
static Speed        speed;

static Transfer * transfer;

void transferInit(USART_TypeDef* _USARTx)
{
  memset(&motorEncoder, 0, sizeof(MotorEncoder));
  memset(&speed, 0, sizeof(Speed));
  transfer = begin(details(speed), details(motorEncoder), _USARTx);
}

void transferLoop()
{
  receiveData(transfer);
}

void sendSpeed(const Speed *_speed)
{
  memcpy(&speed, _speed, sizeof(Speed));
  sendData(transfer);
}

#if defined(_WIN32) || defined(__ICCARM__)
#pragma pack()
#endif